% Written by Dr R�mi Neveu. Any request to remi.neveu@isc.cnrs.fr. Any use must cite the article these analyses refer to
% GLM showing the robustness of the results of figure 1B
ValueFolderTemp='Full path to where the output of the data extraction for journals is stored';
VecValueTime=[1 2 3 4 5 10 0];
VecValueFilter=[1];
VecResultsFigure=[];
for n5=1:size(VecValueTime,2)
    for n6=1:size(VecValueFilter,2)
        ValueTime=VecValueTime(1,n5);
        ValueFilter=VecValueFilter(1,n6);
        n1=32;
        if ValueTime>=1
            if ValueFilter==0
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        else
            if ValueFilter==0
                ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        end
        load([ValueFolderTemp ValueFile]);
        n2=1;
        TestTemp=0;
        while n2<=size(VecResultsArticle2,1)&&TestTemp==0
            if VecResultsArticle2(n2,4)>0
                TestTemp=1;
            end
            n2=n2+1;
        end
        VecValueTemp32=VecResultsArticle2(n2-1:end,:);
        VecValue2Temp32=VecResultsArticle1(n2-1:end,:);
        n1=33;
        if ValueTime>=1
            if ValueFilter==0
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        else
            if ValueFilter==0
                ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        end
        load([ValueFolderTemp ValueFile]);
        n2=1;
        TestTemp=0;
        while n2<=size(VecResultsArticle2,1)&&TestTemp==0
            if VecResultsArticle2(n2,4)>0
                TestTemp=1;
            end
            n2=n2+1;
        end
        VecValueTemp33=VecResultsArticle2(n2-1:end,:);
        VecValue2Temp33=VecResultsArticle1(n2-1:end,:);
        VecResults=[];
        VecResults2=[];
        for n1=1:33
            if n1~=32
                if ValueTime>=1
                    if ValueFilter==0
                        ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
                    else
                        ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                    end
                else
                    if ValueFilter==0
                        ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
                    else
                        ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                    end
                end
                ValueFileTemp=dir([ValueFolderTemp ValueFile]);
                load([ValueFolderTemp ValueFile]);
                n2=1;
                TestTemp=0;
                while n2<=size(VecResultsArticle2,1)&&TestTemp==0
                    if VecResultsArticle2(n2,4)>0
                        TestTemp=1;
                    end
                    n2=n2+1;
                end
                VecValueTemp=VecResultsArticle2(n2-1:end,:);
                VecValue2Temp=VecResultsArticle1(n2-1:end,:);
                if VecValueTemp(1,3)>0&&VecValue2Temp(1,3)>0
                    % Year of the luanch of the new journal-year before the year of the launch of the new journal
                    VecResults=[VecResults;VecValueTemp(1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,1)+VecValueTemp(1,1) -size(VecValueTemp,1)+1];
                    if size(VecValueTemp,1)>1
                        % Year after the the year of the launch of a new journal-year before the year of the launch of the new journal
                        VecResults2=[VecResults2;VecValueTemp(2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,1)+VecValueTemp(2,1) -size(VecValueTemp,1)+1];
                    end
                end
            end
        end
        [ValueResults,stats]=robustfit(VecResults(:,end),VecResults(:,7)-VecResults(:,6));
        VecResultsFigure=[VecResultsFigure;ValueResults' stats.se' stats.p'];
    end
end
VecValueTime=[2];
VecValueFilter=[0];
for n5=1:size(VecValueTime,2)
    for n6=1:size(VecValueFilter,2)
        ValueTime=VecValueTime(1,n5);
        ValueFilter=VecValueFilter(1,n6);
        n1=32;
        if ValueTime>=1
            if ValueFilter==0
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        else
            if ValueFilter==0
                ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        end
        load([ValueFolderTemp ValueFile]);
        n2=1;
        TestTemp=0;
        while n2<=size(VecResultsArticle2,1)&&TestTemp==0
            if VecResultsArticle2(n2,4)>0
                TestTemp=1;
            end
            n2=n2+1;
        end
        VecValueTemp32=VecResultsArticle2(n2-1:end,:);
        VecValue2Temp32=VecResultsArticle1(n2-1:end,:);
        n1=33;
        if ValueTime>=1
            if ValueFilter==0
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        else
            if ValueFilter==0
                ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
            else
                ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
            end
        end
        load([ValueFolderTemp ValueFile]);
        n2=1;
        TestTemp=0;
        while n2<=size(VecResultsArticle2,1)&&TestTemp==0
            if VecResultsArticle2(n2,4)>0
                TestTemp=1;
            end
            n2=n2+1;
        end
        VecValueTemp33=VecResultsArticle2(n2-1:end,:);
        VecValue2Temp33=VecResultsArticle1(n2-1:end,:);
        VecResults=[];
        VecResults2=[];
        for n1=1:33
            if n1~=32
                if ValueTime>=1
                    if ValueFilter==0
                        ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
                    else
                        ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                    end
                else
                    if ValueFilter==0
                        ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
                    else
                        ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                    end
                end
                ValueFileTemp=dir([ValueFolderTemp ValueFile]);
                load([ValueFolderTemp ValueFile]);
                n2=1;
                TestTemp=0;
                while n2<=size(VecResultsArticle2,1)&&TestTemp==0
                    if VecResultsArticle2(n2,4)>0
                        TestTemp=1;
                    end
                    n2=n2+1;
                end
                VecValueTemp=VecResultsArticle2(n2-1:end,:);
                VecValue2Temp=VecResultsArticle1(n2-1:end,:);
                if VecValueTemp(1,3)>0&&VecValue2Temp(1,3)>0
                    % Year of the luanch of the new journal-year before the year of the launch of the new journal
                    VecResults=[VecResults;VecValueTemp(1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+1,1)+VecValueTemp(1,1) -size(VecValueTemp,1)+1];
                    if size(VecValueTemp,1)>1
                        % Year after the the year of the launch of a new journal-year before the year of the launch of the new journal
                        VecResults2=[VecResults2;VecValueTemp(2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,1)/VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,3) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1),1) VecValueTemp32(size(VecValueTemp32,1)-size(VecValueTemp,1)+2,1)+VecValueTemp(2,1) -size(VecValueTemp,1)+1];
                    end
                end
            end
        end
        [ValueResults,stats]=robustfit(VecResults(:,end),VecResults(:,7)-VecResults(:,6));
    end
end
VecValueFigure=[VecResults(:,7) VecResults(:,6) VecResults(:,end)+2020 VecResults(:,7)./(VecResults(:,3)+VecResults(:,1))*100 VecResults(:,6)./VecResults(:,2)*100];
[ValueResults,stats]=robustfit(VecResults(:,end),VecResults(:,7)-VecResults(:,6));
% save([ValueFolderTemp 'FichierFigureRobustnessStartNewJournal.mat'],'VecResultsFigure','VecValueFigure','ValueResults','stats');
